package com.snail.manager.user.controller;


import com.snail.manager.user.entity.User;
import com.snail.manager.user.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;


@Controller
public class ActiveController {

    @Autowired
    private UserService userService;
    @RequestMapping(value = "/javamail/ActiveServlet")
    public String eactiveUser(@RequestParam("code") String code){
        System.out.println("++++++++++++++++激活开始");
        List<User> list = userService.getUserByCode(code);
        if (list.isEmpty()||list.size()==0){
            return "failure";
        }else {
            User user = list.get(0);
            user.setCode(null);
            user.setState(true);
            userService.updateUser(user);
            return "success";
        }

    }
}
